
class Node
{
public:
    int val;
    vector<Node *> children;

    Node() {}

    Node(int _val)
    {
        val = _val;
    }

    Node(int _val, vector<Node *> _children)
    {
        val = _val;
        children = _children;
    }
};

#include <vector>
#include <queue>
using namespace std;
class Solution
{
public:
    vector<vector<int>> levelOrder(Node *root)
    {
        if (!root)
            return {};
        queue<Node *> q;
        vector<vector<int>> ans;
        q.push(root);
        int num = 1;
        while (q.size())
        {
            vector<int> tmp;
            while (num--)
            {
                auto tt = q.front();
                tmp.push_back(tt->val);
                for (auto e : tt->children)
                    if (e)
                        q.push(e);
                q.pop();
            }
            ans.push_back(move(tmp));
            num = q.size();
        }
        return ans;
    }
};